package guiElements;

import java.util.Comparator;

public class FabricComparator implements Comparator<Fabric> {

	private String compareField;

	public FabricComparator(String compareField) {
		this.compareField = compareField;
	}

	@Override
	public int compare(Fabric fabricOne, Fabric fabricTwo) {
		if (compareField.equalsIgnoreCase("fabricName")) {
			if (fabricOne.getFabricName().equalsIgnoreCase(
					fabricTwo.getFabricName())) {
				return fabricOne.getColorWayName().compareToIgnoreCase(
						fabricTwo.getColorWayName());
			} else
				return fabricOne.getFabricName().compareToIgnoreCase(
						fabricTwo.getFabricName());
		} else if (compareField.equalsIgnoreCase("fabricColor")) {
			if (fabricOne.getPrimaryColor().equalsIgnoreCase(
					fabricTwo.getPrimaryColor())) {
				if (fabricOne.getSecondaryColor().equalsIgnoreCase(
						fabricTwo.getSecondaryColor())) {
					return fabricOne.getTertiaryColor().compareToIgnoreCase(
							fabricTwo.getTertiaryColor());
				} else
					return fabricOne.getSecondaryColor().compareToIgnoreCase(
							fabricTwo.getSecondaryColor());
			} else
				return fabricOne.getPrimaryColor().compareToIgnoreCase(
						fabricTwo.getPrimaryColor());
		} else if (compareField.equalsIgnoreCase("fabricPattern")) {
			if (fabricOne.getPatternOne().equalsIgnoreCase(
					fabricTwo.getPatternOne())) {
				return fabricOne.getPatternTwo().compareToIgnoreCase(
						fabricTwo.getPatternTwo());
			} else
				return fabricOne.getPatternOne().compareToIgnoreCase(
						fabricTwo.getPatternOne());
		} else
			return (Integer) null;
	}

}
